/**
 * 
 */
package com.abel.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.abel.web.view.HelpfulInfoViewBean;

/**
 * @author admin
 *
 */
public class HelpfulInfoViewValidator implements Validator {

	/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	@Override
	public boolean supports(Class clazz) {
		
		return HelpfulInfoViewBean.class.equals(clazz);
	}

	/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */
	@Override
	public void validate(Object obj, Errors errors) {

		HelpfulInfoViewBean viewBean = (HelpfulInfoViewBean)obj;
		
		if (viewBean.getHowMuchTravel() != null 
				&& !viewBean.getHowMuchTravel().equals("")) {
			
			try {
				Integer.parseInt(viewBean.getHowMuchTravel());
			}
			catch (Exception e) {
				errors.rejectValue("howMuchTravel", "error.null", null, "How much to travel should have a numeric value");
			}
			
		}
	}

}
